package domain;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.Valid;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Access(AccessType.PROPERTY)
public class Registration extends DomainEntity {
	//Constructors
	public Registration() {
		super();
		workUpdates = new HashSet<WorkUpdate>();
	}
	//Attributes
	private Date registrationMoment;
	private double totalAmountOfWork;


	@NotNull
	@Past
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
	public Date getRegistrationMoment() {
		return registrationMoment;
	}

	public void setRegistrationMoment(Date registrationMoment) {
		this.registrationMoment = registrationMoment;
	}

	@Digits(integer = 9, fraction = 2)
	@Min(0)
	public double getTotalAmountOfWork() {
		return totalAmountOfWork;
	}

	public void setTotalAmountOfWork(double totalAmountOfWork) {
		this.totalAmountOfWork = totalAmountOfWork;
	}

	// Relationships

	private User user;
	private Project project;
	private Collection<WorkUpdate> workUpdates;

	@Valid
	@NotNull
	@ManyToOne(optional = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Valid
	@NotNull
	@ManyToOne(optional = false)
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	@OneToMany(mappedBy = "registration")
	public Collection<WorkUpdate> getWorkUpdates() {
		return workUpdates;
	}

	public void setWorkUpdates(Collection<WorkUpdate> workUpdates) {
		this.workUpdates = workUpdates;
	}
}
